package ar.com.equis.arquitectura.preloader {
	
	
	import ar.com.equis.arquitectura.util.AsyncMultiCaller;
	
	import flash.events.Event;
	import flash.events.ProgressEvent;
	
	import mx.core.IUIComponent;
	
	public class EquisInitializer extends AsyncMultiCaller {
		
		public static const INSTANCE:EquisInitializer = new EquisInitializer;
		
		public function EquisInitializer() {
		}

		private var app:IUIComponent;
	    private var preloader:EquisPreloader;
	    
		public function init(app:IUIComponent):void {
			this.app = app;
			execute();
		}

		public function loaded(preloader:EquisPreloader):void {
			this.preloader = preloader;
		}

        
		protected override function callback(_errorText:String = null):void {
        	EquisPreloader.initHandler.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, 1 + (totalCalls - pendingCalls), totalCalls));
        	super.callback(_errorText);
        }
        
        protected override function doFinish():void {
        	EquisPreloader.initHandler.dispatchEvent(new Event(Event.COMPLETE));
        	super.doFinish();
        }
	}
}